package com.jinbooks.persistence.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinbooks.entity.merchant.Merchant;
import com.jinbooks.entity.merchant.dto.MerchantPageDto;
import com.jinbooks.entity.merchant.vo.MerchantVo;
import com.jinbooks.persistence.mapper.MerchantMapper;
import com.jinbooks.persistence.service.MerchantService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户服务实现
 *
 * @author lingma
 */
@Service
@RequiredArgsConstructor
public class MerchantServiceImpl implements MerchantService {
    private final MerchantMapper baseMapper;

    @Override
    public Page<MerchantVo> pageList(MerchantPageDto dto) {
        return baseMapper.merchantPageList(dto.build(), dto);
    }

    @Override
    public List<MerchantVo> treeList(String workspaceId) {
        return baseMapper.selectMerchantTreeList(workspaceId);
    }

    @Override
    public MerchantVo getById(String id, String workspaceId) {
        return baseMapper.getMerchantById(id, workspaceId);
    }

    @Override
    public Boolean save(Merchant dto) {
        return baseMapper.insert(dto) > 0;
    }

    @Override
    public Boolean update(Merchant dto) {
        return baseMapper.updateById(dto) > 0;
    }

    @Override
    public Boolean deleteByIds(List<String> ids) {
        return baseMapper.deleteByIds(ids) > 0;
    }
}